<?php $count = count($array)-1; 
			
?>
<select class="zwc_good_category_g" name="{$name}" onchange="yj_good_category_g(this.value)" >	
				<option value="0">请选择</option>
				<volist name="good_category" id="v">
				 <option <if condition="$array[$count] eq $v['id']">selected</if> value="{$v['id']}">{$v['name']}</option>
				</volist>
</select>	
<?php 
$b = -1;
$c = array('zwc_good_category_p','zwc_good_category');
$d = array('yj_good_category_p','');
for($a=$count;$a>0;$a--){
			$good_category = M($name)->where(array('pid'=>$array[$a]))->select();
			$b++;	
 ?>			
			<select class="{$c[$b]}"  onchange="{$d[$b]}(this.value)" >	
				<option value="0">请选择</option>
				<volist name="good_category" id="v">
				 <option <if condition="$array[$a-1] eq $v['id']">selected</if> value="{$v['id']}">{$v['name']}</option>
				</volist>
			</select>	
<?php 
} 
	$good_category = M($name)->where(array('pid'=>$array[0]))->select();
	if($good_category){
	$b++;
?>
		<select class="{$c[$b]}"   onchange="{$d[$b]}(this.value)" >	
				<option value="0">请选择</option>
				<volist name="good_category" id="v">
				 <option <if condition="$array[$a-1] eq $v['id']">selected</if> value="{$v['id']}">{$v['name']}</option>
				</volist>
		</select>	

<?php 
	}
?>	
		
			


<script>
var name = '{$name}';

function yj_good_category_g(id){
	if(id == 0){
		$('.zwc_good_category').remove();
		$('.zwc_good_category_p').remove();
		return false;
	}
	$.post("{:addons_url('Yjategory://Yjategory/ajax')}",{'name':name,'id':id},function(data){
			var string = '';
			var count = data.length;
			if(count!==0){
						string = "<select class='zwc_good_category_p'  onchange='yj_good_category_p(this.value)'>";
						string = string + "<option value='0'>请选择</option>";
					for(var i = 0;i<count;i++){
						string = string + '<option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
					}
						string = string + '</select>';
			}
			$('.zwc_good_category_p').remove();
			$('.zwc_good_category_g').after(string);
			
	})
	
	
}
function yj_good_category_p(id){
		if(id == 0){
		$('.zwc_good_category').remove();
		$('.zwc_good_category_p').attr('name','');
		return false;
		}
		$('.zwc_good_category_p').attr('name',name);
		$.post("{:addons_url('Yjategory://Yjategory/ajax')}",{'name':name,'id':id},function(data){
			var string = '';
			var count = data.length;
			if(count!==0){
						string = "<select  onchange ='yj_good_category(this.value)' class='zwc_good_category' >";
							string = string + "<option value='0'>请选择</option>";
					for(var i = 0;i<count;i++){
						string = string + '<option value="'+data[i]['id']+'">'+data[i]['name']+'</option>'
					}
						string = string + '</select>';
			}
			$('.zwc_good_category').remove();
			$('.zwc_good_category_p').after(string);
			
	})
		
		
}
function yj_good_category(id){
	id == 0?$('.zwc_good_category').attr('name',''):$('.zwc_good_category').attr('name',name);
}
</script>
